Skip to content

Add -KillTreeOnExit: kill what a program left running when it exits - #87

Merged
HalRiveria-Bot merged 2 commits into
mainfrom
fix/kill-tree-on-exit
Nov 30, 2026
Merged

HalRiveria-Bot merged 2 commits into
mainfrom
fix/kill-tree-on-exit

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

A program that exits while something it started (a start /b helper, say) holds its output open makes its job wait out -StreamTimeoutMs, and the helper lives on until it ends or PowerShell does. There was no way to say "take it with you".

  • -KillTreeOnExit on Invoke-PkProcessWithTimeout, Invoke-PkProcessBatch and Invoke-PkProcessDispatch kills whatever a program left running once it exits, through the program's own Job Object and before the wait for its output. Off by default, since some tools leave a build server or a daemon running on purpose.
  • A command's or job's own KillTreeOnExit key ($true/$false) overrides it either way. A bad value is a failed start, refused before the starter runs.
  • The dispatcher's default poll does the kill; with a custom -JobPollCompleted, Complete-PkProcess does. An abort's force-stop also takes what an already-exited program left. It works with custom starters that use Start-PkProcess.
  • A program without a Job Object of its own is left alone, with no warning. In AddedToJob mode a child started straight away can be missed. The help and README say so.
  • The dispatcher uses one more key on each job, KillTree.

Tested

New harness section BJ, on both start paths: a program that exits with code 5 and leaves a ping holding its output. It covers each function, both keys in both directions, a leftover that holds no output, custom starter, custom poll, no tree job, force-stop, a worker, and that the default is unchanged.

  • Before (5.1 and 7): 20 of the section's assertions failed. Most because the parameter didn't exist; with only the KillTreeOnExit key set, the ping kept running and the job took 16 s with StreamTimedOut.
  • After: all pass; those jobs end in about 1 s with their output whole and nothing left running.
  • Full harness: ALL PASSED (663 assertions, none skipped) on Windows PowerShell 5.1, then PowerShell 7, in fresh processes.

🤖 Generated with Claude Code

HalRiveria and others added 2 commits November 30, 2026 14:46
On Invoke-PkProcessWithTimeout, Invoke-PkProcessBatch and
Invoke-PkProcessDispatch, plus a KillTreeOnExit key per command. Through the
program's own Job Object, before the wait for its output, so a leftover
child can't hold that up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit a441751 into main Nov 30, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/kill-tree-on-exit branch November 30, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants